package top.xcxdl.rural.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import top.xcxdl.rural.entity.RuralExamination;
import top.xcxdl.rural.entity.RuralUser;
import top.xcxdl.rural.mapper.RuralExaminationMapper;
import top.xcxdl.rural.service.IRuralExaminationService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import top.xcxdl.rural.utils.ImageAddress;

import java.util.List;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author Ding
 * @since 2022-05-07
 */
@Service
public class RuralExaminationServiceImpl extends ServiceImpl<RuralExaminationMapper, RuralExamination> implements IRuralExaminationService {

    @Override
    public PageInfo<RuralExamination> getList(Integer pageNo, Integer pageSize, String key) {
        PageHelper.startPage(pageNo, pageSize);
        List<RuralExamination> list = baseMapper.getList(key);
        return new PageInfo<>(list);
    }

    @Override
    public RuralExamination getDetail(Integer examId) {
        return baseMapper.getDetail(examId);
    }

    @Override
    public int doEdit(RuralExamination examination) {
        examination.setUpdateTime(String.valueOf(System.currentTimeMillis() / 1000));
        if (examination.getExamId() != null) {
            return baseMapper.updateById(examination) + 1;
        } else {
            examination.setCreateTime(String.valueOf(System.currentTimeMillis() / 1000));
            return baseMapper.insert(examination);
        }
    }

    @Override
    public int doDelete(List<Integer> ids) {
        QueryWrapper<RuralExamination> wrapper = new QueryWrapper<>();
        wrapper.in("exam_id", ids);
        return baseMapper.delete(wrapper);
    }
}
